package com.ruoyi.product.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductActivityCategory;
import com.ruoyi.product.service.IProductActivityCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动自定义分类Controller
 * 
 * @author liuhuizhong
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/product/productActivityCategory")
public class ProductActivityCategoryController extends BaseController
{
    @Autowired
    private IProductActivityCategoryService productActivityCategoryService;

    /**
     * 查询活动自定义分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductActivityCategory productActivityCategory)
    {
        startPage();
        List<ProductActivityCategory> list = productActivityCategoryService.selectProductActivityCategoryList(productActivityCategory);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:listByActivityId')")
    @GetMapping("/listByActivityId")
    public TableDataInfo listByActivityId(Long activityId)
    {
        List<ProductActivityCategory> list = productActivityCategoryService.getActivityCategoryListByActivityId(activityId);
        return getDataTable(list);
    }

    /**
     * 导出活动自定义分类列表
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:export')")
    @Log(title = "活动自定义分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductActivityCategory productActivityCategory)
    {
        List<ProductActivityCategory> list = productActivityCategoryService.selectProductActivityCategoryList(productActivityCategory);
        ExcelUtil<ProductActivityCategory> util = new ExcelUtil<ProductActivityCategory>(ProductActivityCategory.class);
        util.exportExcel(response, list, "活动自定义分类数据");
    }

    /**
     * 获取活动自定义分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:query')")
    @GetMapping(value = "/{customCategoryId}")
    public AjaxResult getInfo(@PathVariable("customCategoryId") Long customCategoryId)
    {
        return success(productActivityCategoryService.selectProductActivityCategoryByCustomCategoryId(customCategoryId));
    }

    /**
     * 新增活动自定义分类
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:add')")
    @Log(title = "活动自定义分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductActivityCategory productActivityCategory)
    {
        return toAjax(productActivityCategoryService.insertProductActivityCategory(productActivityCategory));
    }

    /**
     * 修改活动自定义分类
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:edit')")
    @Log(title = "活动自定义分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductActivityCategory productActivityCategory)
    {
        return toAjax(productActivityCategoryService.updateProductActivityCategory(productActivityCategory));
    }

    /**
     * 删除活动自定义分类
     */
    @PreAuthorize("@ss.hasPermi('product:productActivityCategory:remove')")
    @Log(title = "活动自定义分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customCategoryIds}")
    public AjaxResult remove(@PathVariable Long[] customCategoryIds)
    {
        return toAjax(productActivityCategoryService.deleteProductActivityCategoryByCustomCategoryIds(customCategoryIds));
    }
}
